package com.fyzk.betzhushu.dlt;

import java.math.BigInteger;
import java.util.List;

import com.fyzk.activity.lottery.shuzicai.BallInfo;
import com.fyzk.betzhushu.ZhuShuBase;

public class DLT_Dan_ZhuShu extends ZhuShuBase{

	@Override
	public long betZhuShu(List<List<BallInfo>> balls) {
		int dan_hong = 0;
		int dan_lan = 0;
		int hong = 0;
		int lan = 0;
		
		for (int i = 0; i < balls.size(); i++) {
			List<BallInfo> infos = balls.get(i);
			int selectedNum = 0;
			for (int j = 0; j < infos.size(); j++) {
				BallInfo info = infos.get(j);
				if (info.isSelected()) {
					selectedNum++;
				}
			}
			switch (i) {
			case 0:
				dan_hong = selectedNum;
				break;
			case 1:
				hong = selectedNum;
				break;
			case 2:
				dan_lan = selectedNum;
				break;
			case 3:
				lan = selectedNum;
				break;
			default:
				break;
			}
		}
		
		return getZhuShu_Dan(dan_hong, hong, dan_lan, lan);
	}
	
	/**
	 * 计算胆拖注数
	 */
	private long getZhuShu_Dan(int dan_hong, int hong, int dan_lan, int lan){
		if (dan_hong > 0 && dan_hong < 5 && hong > 1 && (dan_hong + hong) > 5 && lan > 1) {
			BigInteger big = c_x_y(hong).divide(c_x_y(5 - dan_hong)).divide(c_x_y(hong - (5 - dan_hong)));
			BigInteger big_lan = c_x_y(lan).divide(c_x_y(2 - dan_lan)).divide(c_x_y(lan - (2 - dan_lan)));
			return  big.longValue()* big_lan.longValue();
		}else{
			return 0;
		}
	}
	
	private BigInteger c_x_y(int n){
		BigInteger big = new BigInteger(""+n);
		
		return (n == 0) ? new BigInteger("1") : big.multiply(c_x_y(n - 1)) ;
	}

}
